package com.hds.modules.sys.service.base.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hds.common.utils.PageUtils;
import com.hds.common.utils.Query;
import com.hds.modules.sys.dao.base.EsurerSmsRecordsDao;
import com.hds.modules.sys.dao.base.EsurerUserDao;
import com.hds.modules.sys.entity.esurer.EsurerSmsRecordsEntity;
import com.hds.modules.sys.entity.esurer.EsurerUserEntity;
import com.hds.modules.sys.service.base.EsurerSmsRecordsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("esurerSmsRecordsService")
public class EsurerSmsRecordsServiceImpl extends ServiceImpl<EsurerSmsRecordsDao, EsurerSmsRecordsEntity> implements EsurerSmsRecordsService{

	@Autowired
	private EsurerSmsRecordsDao recordsDao;

	@Autowired
	private EsurerUserDao userDao;

	@Override
	public PageUtils queryPage(Map<String, Object> params) {

		String username = (String)params.get("username");
		String mobile = (String)params.get("mobile");

		Page<EsurerSmsRecordsEntity> page = this.selectPage(
				new Query<EsurerSmsRecordsEntity>(params).getPage(),
				new EntityWrapper<EsurerSmsRecordsEntity>()
		);
		List<EsurerSmsRecordsEntity> records = page.getRecords();

		for (EsurerSmsRecordsEntity record: records) {
			EsurerUserEntity user = userDao.selectById(record.getUid());
			user.setNums(recordsDao.getSendNums(user.getId()));
			record.setUser(user);
		}
		page.setRecords(records);

		return new PageUtils(page);
	}


}
